<html>
<head>
	<meta charset='utf-8' />
	<title>记事本</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#content{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body style='padding:0;margin:0;background:#eee'>
<!-- 1 Content容器 -->
<div id='Content' style='border:0px solid'>

	<h1 style='text-align:center'>用户登陆</h1>

	<div style='display:flex;margin:20px auto;width:250px;border:0px solid'>
		<div style=''>用户名：</div>
		<div style='flex:1'>
			<input type="text" id='user' style='width:100%' />
		</div>
	</div>
	<div style='display:flex;margin:20px auto;width:250px;border:0px solid'>
		<div style=''>密　码：</div>
		<div style='flex:1'>
			<input type="password" id='pwd'  style='width:100%' />
		</div>
	</div>

	<div style='text-align:center'>
		<button type='button' id='login' >登陆</button>　
		<button type='button' id='reset'>重置</button>
	</div>

</div><!-- 1 Content容器结束 -->


</body>
</html>
<script src='public/jquery.js'></script>
<script src='public/fun.js'></script>
<script>
$(function(){
	$('#reset').click(function(){
		$('#user,#pwd').val('');
	});

	if(sessionStorage.token1 && sessionStorage.user){
		location.replace('index.html');
		return;
	}

	$('#login').click(function(){
		var user = $('#user').val().trim();
		var pwd = $('#pwd').val().trim();

		var data = {
			type:'login',
			user:user,
			pwd:pwd
		}
		Ajax(data,function(res){
			C(res);
			if(!/^{.*}$/.test(res)){
				A('请求异常！');
				return;
			}
			var tmp = JSON.parse(res);

			if(tmp.stat == 'ok'){
				sessionStorage.token1 = tmp.token1;
				sessionStorage.user = user;
				A('登陆成功！');
				location.replace('index.html');
			}else{
				A('用户名或密码不正确！');
			}

		});

	});

	
});
</script>